﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CollegeShop.Infrastructure.Entities.Repository;

namespace CollegeShop.Infrastructure.Entities.Entity
{
    public class SaleList : IAccessible<T_SaleList, SaleList>, ILogicEntity<T_SaleList, SaleList>
    {
        public int Id { get; set; }

        public string Title { get; set; }

        public int ResourceId { get; set; }

        public int GoodsCategoryID { get; set; }

        public decimal Price { get; set; }

        #region 
        public Resource Resource { get; set; }
        #endregion

        protected override void Covariant(T_SaleList model)
        {
            if (model != null)
            {
                this.Id = model.Id;
                this.Title = model.Title;
                this.ResourceId = model.ResourceId;
                this.GoodsCategoryID = model.GoodsCategoryID;
                this.Price = model.Price;
            }
        }

        protected override T_SaleList Inverter(SaleList model)
        {
            if (model != null)
            {
                return new T_SaleList()
                {
                    GoodsCategoryID = model.GoodsCategoryID,
                    Id = model.Id,
                    Price = model.Price,
                    ResourceId = model.ResourceId,
                    Title = model.Title
                };
            }
            return null;
        }

        public SaleList LoadResource(T_Resource resource)
        {
            this.Resource = new Resource().Set(resource);
            return this;
        }

        public SaleList Set(T_SaleList dbModel)
        {
            Covariant(dbModel);
            return this;
        }
    }
}
